package com.tiantianyuegou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.tiantianyuegou.R;
import com.tiantianyuegou.model.ScreenStoreModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 筛选店铺
 * Created by huyang on 2016/1/13 0013.
 */
public class ScreenStoreAdapter extends BaseAdapter {

    private Context context;
    private List<ScreenStoreModel> data;


    public ScreenStoreAdapter(Context context) {
        this.context = context;
        data = new ArrayList<>();
    }

    public ScreenStoreAdapter(Context context, List<ScreenStoreModel> data) {
        this.context = context;
        this.data = data;
    }

    public void setData(List<ScreenStoreModel> data) {
        this.data.clear();
        this.data.addAll(data);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ScreenStoreModel model = data.get(position);
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item_storelist, null);
            holder.tv_label= (TextView) convertView.findViewById(R.id.tv_item);
            holder.iv_gou= (ImageView) convertView.findViewById(R.id.iv_gou);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tv_label.setText(model.getLabel());
        holder.iv_gou.setImageResource(R.mipmap.gou);
        boolean isSelect=model.isSelect();
        if (isSelect){
            holder.tv_label.setTextColor(context.getResources().getColor(R.color.textcolor_red));
            holder.iv_gou.setImageResource(R.mipmap.gou);
        }else{
            holder.tv_label.setTextColor(context.getResources().getColor(R.color.textcolor_gray));
            holder.iv_gou.setImageResource(R.mipmap.gou1);
        }
        return convertView;
    }

    class ViewHolder {
        TextView tv_label;
        ImageView iv_gou;
        boolean isSelect;
    }
}
